package cn.edu.javaweb.superServlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import cn.edu.javaweb.utils.DBUtil;
@WebServlet("/DeleteNotice")
public class DeleteNotice extends HttpServlet {
	private static final long serialVersionUID = 1L;
	DBUtil db; //声明对象 一定要赋值  否则空指针异常
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		db = new DBUtil(); //赋值 不会出现空指针异常
		String id = request.getParameter("id"); //获取id值  
		System.out.println(id); 
		String SQL = "delete from notice WHERE id='"+id+"'";
		int result = db.update(SQL); //对应的封装方法是update  调用并执行更新    excuteUpdate  返回值是int 
		System.out.println(SQL);
		response.setContentType("text/html;charset=utf-8");
		PrintWriter pw=response.getWriter();
		pw.write("<script language='javascript'>alert('确认撤销该公告！')</script>");

		request.getRequestDispatcher("/SelectNotice").forward(request, response);
	}


	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response); 
	}

}
